import { SET_USER_FETCH_STATUS, SET_USER_INFO } from '@/actionTypes';

/**
 * 用户信息
 * 
 * @param {any} [state={}] 
 * @param {any} action 
 * @returns 
 */
export const user = (state = {}, action) => {
  switch (action.type) {
    case SET_USER_INFO:
      // console.log('设置用户信息 =>>', action.userInfo);
      return Object.assign({}, state, action.userInfo);
    default:
      return state;
  }
};


/**
 * 用户数据请求状态
 * 
 * @param {string} [state='unfetch'] // 'unfetch', 'fetching', 'success', 'error'
 * @param {string} action 
 * @returns 
 */
export const userFetchStatus = (state = 'unfetch', action) => {
  switch (action.type) {
    case SET_USER_FETCH_STATUS:
      return action.status;
    default:
      return state;
  }
};
